import json

from apps.common.base.serializers import *
from apps.merchant.activity.models import *

class ActivityBaseSerializer(BaseSerializer):

    class Meta:
        model = Activity
        fields = "__all__"

class ActivityModelSerializer(BaseSerializer):

    lesseeModel = serializers.SerializerMethodField()
    def get_lesseeModel(self, obj):
        try:
            return {'id': obj.lessee.id, 'name': obj.lessee.name}
        except:
            return {}

    activityParamsObj = serializers.SerializerMethodField()
    def get_activityParamsObj(self, obj):
        rateList = [
            {'id': 1, 'value': 30, 'label': '30天', 'rate': 0.005},
            {'id': 2, 'value': 90, 'label': '90天', 'rate': 0.02},
            {'id': 3, 'value': 180, 'label': '180天', 'rate': 0.045},
            {'id': 4, 'value': 360, 'label': '360天', 'rate': 0.1}
        ]
        try:
            return {
                'rateList': rateList,
            }
        except:
            return ''

    class Meta:
        model = Activity
        fields = "__all__"